<?php
@session_start();
$PurviewLevel=2;
$CheckChannelID=0;  
$PurviewLevel_Others="sys_weixin_menu";

require("../../inc/common.inc.php");
require_once("../Admin_ChkPurview.php");
global $MTYPE,$MTYPE2;
$MTYPE=array("0"=>"点击","1"=>"网址");
$MTYPE2=array("0"=>"click","1"=>"view");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<TITLE>铭讯EOS网站后台管理</TITLE>
<Meta name="Keywords" Content="济南网站建设 济南网站制作 山东网站建设 济南铭讯软件有限公司">
<Meta name="Description" Content="济南网站制作：铭讯软件专业服务优秀企业，致力于网站建、设网站推广、网络营销一体的全访位网络服务商">
<link rel="stylesheet" href="../images/style.css" type="text/css">
<script type="text/javascript" src="../js/tuisong.js"></script>
</head>
<?php if ($actions=="add" or $actions=="modi"){?>
<script>
var arr=new Array();
<?php
$menufuarr="";
$rs=$db->excu("select * from mx_weixin_menu where fid='0' order by orderid asc, id asc");
if ($db->num_rows($rs)>0 ){
	while($rsdb=$db->fetch_array($rs)){
	$havenum=$db->listcount("mx_weixin_menu"," and fid='$rsdb[id]' ");
	$menufuarr[$rsdb["id"]]=$rsdb["mname"];
?>
arr[<?php echo $rsdb["id"]?>]=<?php echo (float)$havenum;?>; 
<?php
	}
}
?>
function show_url(){
	var thisvalue = 0;
	var idObj=document.form1.mtype;
	for(var i=0;i<idObj.length;i++){
		if(idObj[i].checked){
			thisvalue=idObj[i].value;
		}
	}
	if(thisvalue==1){
		document.getElementById("sucaitr").style.display="none";	
		document.getElementById("urltr").style.display="block";	
	}else{
		document.getElementById("sucaitr").style.display="block";	
		document.getElementById("urltr").style.display="none";	
	}
}

function switchmod(modtag,modtagclass1,modtagclass2,modk,modknum)
{
	document.getElementById("rtype").value=modk;
	document.getElementById("rsucaiid").value=0;
	document.getElementById("rmsgid").value=0;
	for(i=1; i <=modknum; i++)
	{
		content=modtag+"_list"+i;
		if (i==modk)
		{
			document.getElementById(modtag+i).className=modtagclass1;
			document.getElementById(content).style.display="block";
		}
		else
		{
			document.getElementById(modtag+i).className=modtagclass2;
			document.getElementById(content).style.display="none";
		}
		document.getElementById("list"+i).innerHTML="";
	}
}

function showinfo(returnid,changeid,changevalue){
	document.getElementById(changeid).value=changevalue;
	$.ajax({ url: "/mxsoft/tuisong/getinfo.php?id="+changevalue+"&cid="+changeid,success: function(msg){document.getElementById(returnid).innerHTML=msg;}});
}

</script>
<?php }?>
<body> 
<?php
if($actions=="del"){
//删除图片
	if(!$iddb&&!$id){
		$fun->popmassage("请选择要修改的信息","","popback");
		exit();
	}
	elseif(is_array($iddb))
	{
		foreach($iddb AS $key=>$value){
			$menuinfo=$db->getinfo("select * from mx_weixin_menu where id='$key' limit 1");
			if ($menuinfo["fid"]==0){
				$havenum=$db->listcount("mx_weixin_menu"," and fid='$menuinfo[id]' ");
				if ($havenum>0){
				$fun->popmassage("此菜单含有二级子菜单不能删除","","popback");
				exit();
				}
			}
			$db->excu("DELETE FROM mx_weixin_menu WHERE id='$key' ");
		}
	}elseif($id){
		$menuinfo=$db->getinfo("select * from mx_weixin_menu where id='$id' limit 1");
		if ($menuinfo["fid"]==0){
			$havenum=$db->listcount("mx_weixin_menu"," and fid='$menuinfo[id]' ");
			if ($havenum>0){
			$fun->popmassage("此菜单含有二级子菜单不能删除","","popback");
			exit();
			}
		}
		$db->excu("DELETE FROM mx_weixin_menu WHERE id='$id' ");
	}
	$url=$fromurl?$fromurl:$FROMURL;
	jump2("操作成功",$url,1);
	exit();
}
elseif($actions=="list")
{
//更新选中信息排列顺序
	foreach( $listdb AS $key=>$value){
		$db->excu("UPDATE mx_weixin_menu SET orderid='$value' WHERE id='$key'");
	}
	jump2("修改成功","$FROMURL",1);
	exit();
}
elseif($actions=="saveadd")
{
  $fid=intval($fid);
  if($fid>0){
	  //判断子栏目是否超过5个
	  $havenum=$db->listcount("mx_weixin_menu"," and fid='$fid' ");	
	  if($havenum>=5){
	  $fun->popmassage("此菜单二级菜单已经超过5个，请选择其他菜单","","popback");
	  exit();
	  }
  }
  else{
  //判断父栏目是否超过3个
	  $havenum=$db->listcount("mx_weixin_menu"," and fid='0' ");	
	  if($havenum>=3){
	  $fun->popmassage("一级菜单已经超过3个，请删除其他菜单或者将此菜单设置成二级菜单","","popback");
	  exit();
	  }
  }
  if(trim($mname)==""){
		$fun->popmassage("菜单名称不能为空","","popback");
		exit();
  }
  $mtype=intval($mtype);
  if ($mtype==0){
	$rtype = intval($rtype);
	$rsucaiid = intval($rsucaiid);
	$rmsgid = intval($rmsgid);
	if($rtype==5){
		if(trim($rcontent)==""){
		$fun->popmassage("请设置自动回复的内容","","popback");
		exit();
		}
	}elseif($rtype==4){
		if($rmsgid==0){
		$fun->popmassage("请设置自动回复的内容","","popback");
		exit();
		}
	}else{
		if($rsucaiid==0){
		$fun->popmassage("请设置自动回复的内容","","popback");
		exit();
		}
	}
	$murl="";
  }else{
	  if(trim($murl)==""){
			$fun->popmassage("访问链接不能为空","","popback");
			exit();
	  }
	  $rtype=0;
	  $rmsgid=0;
	  $rsucaiid=0;
  }
  
  if ($orderid==""){$orderid=666;}
	$files=array(
	"fid"         =>$fid,
	"mname"       =>$mname,
	"mtype"       =>$mtype,
	"mkey"        =>$mkey,
	"murl"        =>$murl,
	"mttype"      =>$rtype,
	"mtcontent"   =>$rcontent,
	"mtsucaiid"   =>$rsucaiid,
	"mtmsgid"     =>$rmsgid,
	"orderid"     =>$orderid,
	"adddate"     =>date("Y-m-d H:i:s"),
	"addid"       =>$_SESSION['mxadmin']['userid'],
	);
	$db->exe_insert("mx_weixin_menu",$files);
	jump2("菜单添加成功","yx_weixin_menu.php");
	exit();
}
elseif ($actions=="savemodi"){
	$id=intval($id);
    if($id==0){
		$fun->popmassage("请选择要修改的信息","","popback");
		exit();
    }
    $fid=intval($fid);
    if($fid>0){
	  //判断子栏目是否超过5个
	  $havenum=$db->listcount("mx_weixin_menu"," and fid='$fid' and id<>'$id'");	
	  if($havenum>=5){
	  $fun->popmassage("此菜单二级菜单已经超过5个，请选择其他菜单","","popback");
	  exit();
	  }
    }
    else{
    //判断父栏目是否超过3个
	  $havenum=$db->listcount("mx_weixin_menu"," and fid='0' and id<>'$id'");	
	  if($havenum>=3){
	  $fun->popmassage("一级菜单已经超过3个，请删除其他菜单或者将此菜单设置成二级菜单","","popback");
	  exit();
	  }
    }
    if(trim($mname)==""){
		$fun->popmassage("菜单名称不能为空","","popback");
		exit();
    }
    $mtype=intval($mtype);
    if ($mtype==0){
	    $rtype = intval($rtype);
	    $rsucaiid = intval($rsucaiid);
	    $rmsgid = intval($rmsgid);
	    if($rtype==5){
			if(trim($rcontent)==""){
			$fun->popmassage("请设置自动回复的内容","","popback");
			exit();
			}
	    }elseif($rtype==4){
			if($rmsgid==0){
			$fun->popmassage("请设置自动回复的内容","","popback");
			exit();
			}
		}else{
			if($rsucaiid==0){
			$fun->popmassage("请设置自动回复的内容","","popback");
			exit();
			}
		}
		$murl="";
	  }else{
		  if(trim($murl)==""){
				$fun->popmassage("访问链接不能为空","","popback");
				exit();
		  }
		  $rtype=0;
		  $rmsgid=0;
		  $rsucaiid=0;
	  }
  
	if ($orderid==""){$orderid=666;}
	$files=array(
	"fid"         =>$fid,
	"mname"       =>$mname,
	"mtype"       =>$mtype,
	"mkey"        =>$mkey,
	"murl"        =>$murl,
	"mttype"      =>$rtype,
	"mtcontent"   =>$rcontent,
	"mtsucaiid"   =>$rsucaiid,
	"mtmsgid"     =>$rmsgid,
	"orderid"     =>$orderid,
	"modidate"    =>date("Y-m-d H:i:s"),
	"modiid"      =>$_SESSION['mxadmin']['userid'],
	);
	$db->exe_update("mx_weixin_menu",$files,"id='$id'");

	if (trim($gotourl)==""){
	$gotourl=$FROMURL;
	}else{$gotourl=url_code($gotourl);}
	jump2("菜单修改成功","$gotourl",1);
	exit();
}
elseif($actions=="set_wx")
{
	//获取菜单列表
	$menustr="";
	$rs=$db->excu("select * from mx_weixin_menu where fid='0' order by orderid asc, id asc limit 3");
	if ($db->num_rows($rs)<2){
		$fun->popmassage("菜单必须大于2个","","popback");
		exit();
	}
	$bi=0;
	if ($db->num_rows($rs)>0){
		$menustr="{\n\"button\":[\n";
		while ($rsdb=$db->fetch_array($rs)){
			$rs2=$db->excu("select * from mx_weixin_menu where fid='$rsdb[id]' order by orderid asc, id asc limit 5");
			$type=$MTYPE2[$rsdb["mtype"]];
			$name=$rsdb["mname"];
			$key=$rsdb["id"];
			$url=$rsdb["murl"];
			if ($db->num_rows($rs2)>0){
				if ($bi==0){
					$menustr.="{\n\"name\":\"$name\",\n\"sub_button\":[";
				}
				else{
					$menustr.=",{\n\"name\":\"$name\",\n\"sub_button\":[";
				}
				$bi2=0;
				while ($rsdb2=$db->fetch_array($rs2)){
					$type=$MTYPE2[$rsdb2["mtype"]];
					$name=$rsdb2["mname"];
					$key=$rsdb2["id"];
					$url=$rsdb2["murl"];
					if ($type=="view"){$thisstr="\n{\"type\":\"$type\",\n\"name\":\"$name\",\n\"url\":\"$url\"}";}else{$thisstr="\n{\"type\":\"$type\",\n\"name\":\"$name\",\n\"key\":\"$key\"}";}
					if ($bi2==0){
					$menustr.=$thisstr;
					}
					else{
					$menustr.=",".$thisstr;
					}
					$bi2++;
				}
				$menustr.="\n]\n}";
			}
			else{
				if ($type=="view"){$thisstr="{\n\"type\":\"$type\",\n\"name\":\"$name\",\n\"url\":\"$url\"\n}";}else{$thisstr="{\n\"type\":\"$type\",\n\"name\":\"$name\",\n\"key\":\"$key\"}";}
				if ($bi==0){
				$menustr.=$thisstr;
				}
				else{
				$menustr.=",\n".$thisstr;
				}
			}
			$bi++;
		}
		$menustr.="\n]\n}";
	}

	if ($menustr!=""){
		$e=wx_menu_delete();
		if (!$e){
			$fun->popmassage("删除原有菜单失败","","popback");
			exit();
		}
		$e=wx_menu_update($menustr);
		if($e){
			jump2("菜单更新成功","yx_weixin_menu.php",1);
			exit();
		}
		else{
			$fun->popmassage("生成菜单失败","","popback");
			exit();
		}
	}
	else{
		$fun->popmassage("生成菜单失败","","popback");
		exit();
	}
}
?>
<?php require("../mx_head.php");?>
<div class="right">
<?php if ($actions=="add"){?>
<div class="xm2">
<h1 class="fl">添加菜单</h1>
</div>
<div class="xm2_b">
<div class="height10"></div>
<table width='100%' cellspacing='1' cellpadding='5' class="table_southidc">
  <form name="form1" method="post" action="yx_weixin_menu.php?actions=saveadd" onSubmit="return  check();">
    <tr class="list"> 
      <td width='20%'>所属菜单：</td>
      <td colspan="2">
	  <select name="fid" id="fid">
	  <option value="">一级菜单</option>
	  <?php
	  echo show_select($menufuarr,$fid);
	  ?>
	  </select>
	  </td>
    </tr>
    <tr class="list"> 
      <td>菜单名称：</td>
      <td colspan="2"> 
        <input class=mmcinb type='text' name='mname' id="mname" value='<?php echo $rsdb[name]?>' size="60">      </td>
    </tr>
    <tr class="list"> 
      <td>菜单设置：</td>
      <td colspan="2">
	  <table cellpadding="0" height="30" cellspacing="0" border="0">
	  <tr><td>
	  <input type="radio" name="mtype" value="0" onclick="show_url();" checked="checked" />&nbsp;点击菜单
	  <input type="radio" name="mtype" value="1" onclick="show_url();" />&nbsp;网页菜单
	  <input type="hidden" name="rtype" id="rtype" value="1">
	  <input type="hidden" name="rsucaiid" id="rsucaiid" value="0">
	  <input type="hidden" name="rmsgid" id="rmsgid" value="0">
	  </td></tr>
	  </table>
	  <table cellpadding="0" height="30" cellspacing="0" border="0" id="urltr" style="display:none;">
	  <tr> 
	  <td>访问链接：</td>
	  <td colspan="2"><input type='text' name='murl' id="murl" size='50'></td>
	  </tr>
	  </table>
	  <table cellpadding="0" cellspacing="0" border="0" id="sucaitr">
                    <tr class="list">
                      <td colspan="2" height="40">
                      <input type="button" class="button" value="语音" id="tab_1" onclick="switchmod('tab_','button','button2',1,5)">&nbsp;
                      <input type="button" class="button2" value="图片" id="tab_2" onclick="switchmod('tab_','button','button2',2,5)">&nbsp;
                      <input type="button" class="button2" value="视频" id="tab_3" onclick="switchmod('tab_','button','button2',3,5)">&nbsp;
                      <input type="button" class="button2" value="图文消息" id="tab_4" onclick="switchmod('tab_','button','button2',4,5)">
                      <input type="button" class="button2" value="文字" id="tab_5" onclick="switchmod('tab_','button','button2',5,5)">
                      </td>
                    </tr>
                    <tr class="list">
                      <td colspan="2">
                       <style>
					  .tab_box{height:200px; width:90%;line-height:20px;padding:20px; border:#ccc 1px solid;-moz-border-radius:3px;/*仅Firefox支持，实现圆角效果*/-webkit-border-radius:3px;/*仅Safari,Chrome支持，实现圆角效果*/-khtml-border-radius:3px;/*仅Safari,Chrome支持，实现圆角效果*/border-radius:3px;/*仅Opera，Safari,Chrome支持，实现圆角效果*/ overflow-y:auto;}
					  .abutton{ height:30px; line-height:20px; padding-left:20px;}
					  </style>
                      <div id="tab__list1">
                      <p class="abutton"><a href="javascript:showdiv('list1','rsucaiid','tuisong_music_list','语音素材')">点击选取语音素材</a></p>
                      <div id="list1" class="tab_box">
                      </div>
                      </div>
                      <div id="tab__list2" style="display:none;">
                      <p class="abutton"><a href="javascript:showdiv('list2','rsucaiid','tuisong_pic_list','图片素材')">点击选取图片素材</a></p>
                      <div id="list2" class="tab_box">
                      </div>
                      </div>
                      <div id="tab__list3" style="display:none;">
                      <p class="abutton"><a href="javascript:showdiv('list3','rsucaiid','tuisong_video_list','视频素材')">点击选取视频素材</a></p>
                      <div id="list3" class="tab_box">
                      </div>
                      </div>
                      <div id="tab__list4" style="display:none;">
                      <p class="abutton"><a href="javascript:showdiv('list4','rmsgid','tuisong_msg_list','图文消息')">点击选取图文消息</a></p>
                      <div id="list4" class="tab_box">
                      </div>
                      </div>
                      
                      <div id="tab__list5" style="display:none;">
                      <textarea name="rcontent" id="content" style="width:90%;" rows="10"></textarea>
                      <div id="list5">
                      </div>
                      </div>
                      </td>
                    </tr>
	  </table>
	  </td>
    </tr>
    <tr class="list"> 
      <td>菜单排序：</td>
      <td colspan="2"> 
        <input class=mmcinb type='text' name='orderid' id="orderid" value='666' size='20'>      </td>
    </tr>
    <tr class="list"> 
      <td width='19%'></td>
      <td colspan="2"> 
        <input class="button" type='submit' name='Submit' value='提交数据'>
        <input class="button2" type='button' name='back' value='返 回' onclick="history.back();">
		</td>
    </tr>
  </form>
</table>
<div class="height10"></div>
</div>
<script>
function check(){
	if (document.form1.fid.value==""){
		var havelen=0;
		for(i=0;i<=arr.length;i++){
			if (!isNaN(arr[i])){havelen++;}
		}
		if (havelen>=3){
		alert('一级菜单已经超过三个，请选择父菜单或者删除其他一级菜单');
		document.form1.fid.focus();
		return false;
		}
	}else{
		var fid=document.form1.fid.value;
		if (arr[fid]>=5){
			alert('所属菜单已经超过5个二级菜单，请选择其他一级菜单或者删除此菜单内的二级菜单');
			document.form1.fid.focus();
			return false;
		}
	}
	if(!CheckLength("mname","菜单名称")){
		return false;
	}
	var thisvalue = 0;
	var idObj=document.form1.mtype;
	for(var i=0;i<idObj.length;i++){
		if(idObj[i].checked){
			thisvalue=idObj[i].value;
		}
	}
	if(thisvalue==1){
		if(!CheckLength("murl","访问链接")){
			return false;
		}
	}else{
		rtype = document.form1.rtype.value;
		rsucaiid = document.form1.rsucaiid.value;
		rmsgid = document.form1.rmsgid.value;
		rcontent = document.form1.rcontent.value;
		if(rtype==4){
			if(rmsgid==0){
				alert("请设置自动回复的内容");
				return false;
			}
		}
		else if(rtype==5){
			if(rcontent==""){
				alert("请设置自动回复的内容");
				return false;
			}
		}else{
			if(rsucaiid==0){
				alert("请设置自动回复的内容");
				return false;
			}
		}
	}
}
</script>
<?php 
}
elseif ($actions=="modi"){
//修改链接
	$query="SELECT * FROM mx_weixin_menu where id='$id' limit 1";
	$result=$db->excu($query);
	if ($db->num_rows($result)<=0){
		$fun->popmassage("请选择要修改的信息","","popback");
		exit();
	}
	$rsdb=$db->fetch_array($result);
	//获得自动回复信息
	$rtype = $rsdb["mttype"];
	if($rtype==5){
		$returnstr = $rsdb["mtcontent"];
	}elseif($rtype==4){
		$replyinfo = $db->getinfo("select * from mx_sucai_msg where mid = ".$rsdb["mtmsgid"]." limit 1");
		$mpic = $db->getinfo("select fpath from mx_sucai_file where fid = ".$replyinfo["mpic"]." limit 1");
		$mtypestr = $replyinfo["mttype"]==1?"多图文":"单图文";
		$returnstr = '<table width="98%" border="0" align="center" cellpadding="9" cellspacing="1" bgcolor="#CCCCCC" class="stripe">
			  <tr>
                <th width="15%" align="center" class="table_ti">信息类型</th>
				<th align="center" class="table_ti">标题</th>
				<th width="15%" align="center" class="table_ti">封面</th>
                <th width="15%" align="center" class="table_ti">添加时间</th>
			  </tr>
			  <tr>
				<td align="center" bgcolor="#FFFFFF" class="font14">'.$mtypestr.'</td>
				<td align="left" bgcolor="#FFFFFF" class="font14">'.wordscut($replyinfo["mtitle"],80,"...").'</a></td>
				<td align="center" bgcolor="#FFFFFF"><img src="'.get_photourl($mpic["fpath"]).'" style="max-width:100px;"/></td>
				<td align="center" bgcolor="#FFFFFF" class="font12">'.date("Y-m-d",$replyinfo["addtime"]).'</td>
			  </tr>';
		if($replyinfo["mtype"]=1){
		$smsgquery = $db->excu("select * from mx_sucai_msg where fid=".$replyinfo["mid"]." order by addtime,mid");
	
			while($smsgarr = $db->fetch_array($smsgquery)){
				$mpic = $db->getinfo("select fpath from mx_sucai_file where fid = ".$smsgarr["mpic"]." limit 1");
				$returnstr.='<tr>
						<td align="center" bgcolor="#FFFFFF" class="font14"></td>
						<td align="left" bgcolor="#FFFFFF" class="font14">'.wordscut($smsgarr["mtitle"],80,"...").'</a></td>
						<td align="center" bgcolor="#FFFFFF"><img src="'.get_photourl($mpic["fpath"]).'" style="max-width:100px;"/></td>
						<td align="center" bgcolor="#FFFFFF" class="font12">'.date("Y-m-d",$smsgarr["addtime"]).'</td>
					  </tr>';
			}
		}
		$returnstr.='</table>';
	}else{
		$replyinfo = $db->getinfo("select * from mx_sucai_file where fid = '".$rsdb["mtsucaiid"]."' limit 1");
		if($replyinfo["ftype"]==2){
		$returnstr = "<table width='98%' border='0' align='center' cellpadding='9' cellspacing='1' bgcolor='#CCCCCC' class='stripe'>
			  <tr>
                <th align='center' class='table_ti'>素材名称</th>
				<th width='15%' align='center' class='table_ti'>缩略图</th>
                <th width='10%' align='center' class='table_ti'>大小</th>
                <th width='20%' align='center' class='table_ti'>添加时间</th>
			  </tr>
			  <tr>
				<td align='center' bgcolor='#FFFFFF' class='font14'>".$replyinfo['fname']."</td>
				<td align='center' bgcolor='#FFFFFF'><img src='".$replyinfo['fpath']."' style='max-width:100px;'/></td>
                <td align='center' bgcolor='#FFFFFF' class='font14'>".round($replyinfo['fsize']/1024,2)."k</td>
				<td align='center' bgcolor='#FFFFFF' class='font12'>".date('Y-m-d',$replyinfo['addtime'])."</td>
			  </tr>
			</table><br /><br />";
		}else{
		$returnstr = "<table width='98%' border='0' align='center' cellpadding='9' cellspacing='1' bgcolor='#CCCCCC' class='stripe'>
			  <tr>
                <th align='center' class='table_ti'>素材名称</th>
                <th width='10%' align='center' class='table_ti'>大小</th>
                <th width='20%' align='center' class='table_ti'>添加时间</th>
			  </tr>
			  <tr>
				<td align='center' bgcolor='#FFFFFF' class='font14'>".$replyinfo['fname']."</td>
                <td align='center' bgcolor='#FFFFFF' class='font14'>".round($replyinfo['fsize']/1024,2)."k</td>
				<td align='center' bgcolor='#FFFFFF' class='font12'>".date('Y-m-d',$replyinfo['addtime'])."</td>
			  </tr>
			</table><br /><br />";	
}
	}
	if ($gotourl==""){$gotourl=url_encode($_SERVER['HTTP_REFERER']);}
?>
<div class="xm2">
<h1 class="fl">修改菜单</h1>
</div>
<div class="xm2_b">
<div class="height10"></div>
<table width='100%' cellspacing='1' cellpadding='5' class="table_southidc">
  <form name="form1" method="post" action="yx_weixin_menu.php" onSubmit="return  check();">
    <tr class="list"> 
      <td width='20%'>所属菜单：</td>
      <td colspan="2">
	  <select name="fid" id="fid">
	  <option value="">一级菜单</option>
	  <?php
	  echo show_select($menufuarr,$rsdb["fid"]);
	  ?>
	  </select>
	  </td>
    </tr>
    <tr class="list"> 
      <td>菜单名称：</td>
      <td colspan="2"> 
        <input class=mmcinb type='text' name='mname' id="mname" value='<?php echo $rsdb["mname"]?>' size="60"></td>
    </tr>
    <tr class="list"> 
      <td>菜单设置：</td>
      <td colspan="2"> 
	  <table cellpadding="0" height="30" cellspacing="0" border="0">
	  <tr><td>
	  <input type="radio" name="mtype" value="0" onclick="show_url();" <?php if ($rsdb["mtype"]==0){echo "checked";}?>/>&nbsp;点击菜单
	  <input type="radio" name="mtype" value="1" onclick="show_url();" <?php if ($rsdb["mtype"]==1){echo "checked";}?>/>&nbsp;网页菜单
	  <input type="hidden" name="rtype" id="rtype" value="<?php echo $rsdb["mttype"]?>">
	  <input type="hidden" name="rsucaiid" id="rsucaiid" value="<?php echo $rsdb["mtsucaiid"]?>">
	  <input type="hidden" name="rmsgid" id="rmsgid" value="<?php echo $rsdb["mtmsgid"]?>">
	  </td></tr>
	  </table>
	  <table cellpadding="0" height="30" cellspacing="0" border="0" id="urltr" style="display:<?php if ($rsdb["mtype"]==0){echo "none";}?>;">
	  <tr> 
	  <td>访问链接：</td>
	  <td colspan="2"><input type='text' name='murl' id="murl" size='50' value="<?php echo $rsdb["murl"];?>"></td>
	  </tr>
	  </table>
	  <table cellpadding="0" cellspacing="0" border="0" id="sucaitr" <?php if ($rsdb["mtype"]==1){echo "style=\"display:none;\"";}?>>
                    <tr class="list">
                      <td colspan="2" height="40">
                      <input type="button" <?php echo $rsdb["mttype"]==1?'class="button"':'class="button2"';?> value="语音" id="tab_1" onclick="switchmod('tab_','button','button2',1,5)">&nbsp;
                      <input type="button" <?php echo $rsdb["mttype"]==2?'class="button"':'class="button2"';?> value="图片" id="tab_2" onclick="switchmod('tab_','button','button2',2,5)">&nbsp;
                      <input type="button" <?php echo $rsdb["mttype"]==3?'class="button"':'class="button2"';?> value="视频" id="tab_3" onclick="switchmod('tab_','button','button2',3,5)">&nbsp;
                      <input type="button" <?php echo $rsdb["mttype"]==4?'class="button"':'class="button2"';?> value="图文消息" id="tab_4" onclick="switchmod('tab_','button','button2',4,5)">
                      <input type="button" <?php echo $rsdb["mttype"]==5?'class="button"':'class="button2"';?> value="文字" id="tab_5" onclick="switchmod('tab_','button','button2',5,5)">
                      </td>
                    </tr>
                    <tr class="list">
                      <td colspan="2">
                       <style>
					  .tab_box{height:200px; width:90%;line-height:20px;padding:20px; border:#ccc 1px solid;-moz-border-radius:3px;/*仅Firefox支持，实现圆角效果*/-webkit-border-radius:3px;/*仅Safari,Chrome支持，实现圆角效果*/-khtml-border-radius:3px;/*仅Safari,Chrome支持，实现圆角效果*/border-radius:3px;/*仅Opera，Safari,Chrome支持，实现圆角效果*/ overflow-y:auto;}
					  .abutton{ height:30px; line-height:20px; padding-left:20px;}
					  </style>
                      <div id="tab__list1" <?php echo $rsdb["mttype"]!=1?'style="display:none;"':'';?>>
                      <p class="abutton"><a href="javascript:showdiv('list1','rsucaiid','tuisong_music_list','语音素材')">点击选取语音素材</a></p>
                      <div id="list1" class="tab_box">
					  <?php echo $rsdb["mttype"]==1?$returnstr:"";?>
                      </div>
                      </div>
                      <div id="tab__list2" <?php echo $rsdb["mttype"]!=2?'style="display:none;"':'';?>>
                      <p class="abutton"><a href="javascript:showdiv('list2','rsucaiid','tuisong_pic_list','图片素材')">点击选取图片素材</a></p>
                      <div id="list2" class="tab_box">
					  <?php echo $rsdb["mttype"]==2?$returnstr:"";?>
                      </div>
                      </div>
                      <div id="tab__list3"  <?php echo $rsdb["mttype"]!=3?'style="display:none;"':'';?>>
                      <p class="abutton"><a href="javascript:showdiv('list3','rsucaiid','tuisong_video_list','视频素材')">点击选取视频素材</a></p>
                      <div id="list3" class="tab_box">
					  <?php echo $rsdb["mttype"]==3?$returnstr:"";?>
                      </div>
                      </div>
                      <div id="tab__list4" <?php echo $rsdb["mttype"]!=4?'style="display:none;"':'';?>>
                      <p class="abutton"><a href="javascript:showdiv('list4','rmsgid','tuisong_msg_list','图文消息')">点击选取图文消息</a></p>
                      <div id="list4" class="tab_box">
					  <?php echo $rsdb["mttype"]==4?$returnstr:"";?>
                      </div>
                      </div>
                      
                      <div id="tab__list5" <?php echo $rsdb["mttype"]!=5?'style="display:none;"':'';?>>
                      <textarea name="rcontent" id="content" style="width:90%;" rows="10"><?php echo $rsdb["mttype"]==5?$returnstr:"";?></textarea>
                      <div id="list5">
                      </div>
                      </div>
                      </td>
                    </tr>
	  </table>
      </td>
    </tr>
    <tr class="list"> 
      <td>链接排序：</td>
	  <td colspan="2"> 
	  <input class=mmcinb type='text' name='orderid' id="orderid" value='<?php echo $rsdb["orderid"]?>' size='20'>
	  </td>
    </tr>
    <tr class="list"> 
      <td></td>
      <td colspan="2"> 
        <input class="button" type='submit' name='Submit' value='提交数据'>
        <input class="button2" type='button' name='back' value='返 回' onclick="history.back();">
		<input type="hidden" name="id" value="<?php echo $rsdb[id] ?>">
		<input type="hidden" name="gotourl" value="<?php echo $gotourl?>">
		<input type="hidden" name="actions" value="savemodi">      </td>
    </tr>
  </form>
</table>
<div class="height10"></div>
</div>
<script>
function check(){
	<?php
	if ($rsdb["fid"]==0){
	?>
	if (document.form1.fid.value!=""){
		var fid=document.form1.fid.value;
		if (arr[fid]>=5){
			alert('所属菜单已经超过5个二级菜单，请选择其他一级菜单或者删除此菜单内的二级菜单');
			document.form1.fid.focus();
			return false;
		}
	}
	<?php
	}else{
	?>
	if (document.form1.fid.value==""){
		var havelen=0;
		for(i=0;i<=arr.length;i++){
			if (!isNaN(arr[i])){havelen++;}
		}
		if (havelen>=3){
		alert('一级菜单已经超过三个，请选择父菜单或者删除其他一级菜单');
		document.form1.fid.focus();
		return false;
		}
	}else{
		var fid=document.form1.fid.value;
		if (arr[fid]>=5 && fid!=<?php echo $rsdb["fid"]?>){
			alert('所属菜单已经超过5个二级菜单，请选择其他一级菜单或者删除此菜单内的二级菜单');
			document.form1.fid.focus();
			return false;
		}
	}
	<?php }?>
	if(!CheckLength("mname","菜单名称")){
		return false;
	}
	var thisvalue = 0;
	var idObj=document.form1.mtype;
	for(var i=0;i<idObj.length;i++){
		if(idObj[i].checked){
			thisvalue=idObj[i].value;
		}
	}
	if(thisvalue==1){
		if(!CheckLength("murl","访问链接")){
			return false;
		}
	}else{
		rtype = document.form1.rtype.value;
		rsucaiid = document.form1.rsucaiid.value;
		rmsgid = document.form1.rmsgid.value;
		rcontent = document.form1.rcontent.value;
		if(rtype==4){
			if(rmsgid==0){
				alert("请设置自动回复的内容");
				return false;
			}
		}
		else if(rtype==5){
			if(rcontent==""){
				alert("请设置自动回复的内容");
				return false;
			}
		}else{
			if(rsucaiid==0){
				alert("请设置自动回复的内容");
				return false;
			}
		}
	}
}
</script>
<?php 
}

else{
?>
<div class="xm2">
<h1 class="fl">微信菜单</h1>
</div>
<div class="xm2_b" style="border-bottom:0px;">
<div class="t">
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
	<tr>
	<td>
	<div class="an1"><a href="yx_weixin_menu.php?actions=add">添加菜单</a></div>
	<div class="an2"><a href="javascript:document.form1.actions.value='list';document.form1.submit();">更新排序</a></div>
	<div class="an2"><a href="yx_weixin_menu.php?actions=set_wx">更新到微信</a></div>
	</td>
	</tr>
	</table>
</div>
</div>
<div class="xm2_b">
<div class="height10"></div>

<table width='100%' cellspacing='1' cellpadding='3' class="table_southidc">
<form name="form1" method="post" action="yx_weixin_menu.php">
    <tr class="head"> 
      <th align="center">菜单名称</th>
      <th width="17%" align="center">菜单类型</th>
      <th width="8%" align="center">排序</th>
      <th width="20%" align="center">操作</th>
    </tr>
<?php
	$rs=$db->excu("select * from mx_weixin_menu where fid='0' order by orderid, id asc");
	if ($db->num_rows($rs)==0){
		echo "<tr class=\"list\"><td colspan=4 height=30><center>暂无信息</center></td></tr>";
	}
	else{
		while($rsdb=$db->fetch_array($rs)){
?>
    <tr class="list"> 
      <td width="35%"><?php echo $rsdb["mname"]?></td>
      <td width="9%" align="center"><?php echo $MTYPE[$rsdb["mtype"]]?></td>
      <td width="8%" align="center"> 
        <input type="text" name="listdb[<?php echo $rsdb[id] ?>]" size="7" value="<?php echo $rsdb['orderid']?>">
      </td>
      <td width="13%" align="center"><a href="yx_weixin_menu.php?actions=add&fid=<?php echo $rsdb[id]?>">添加子菜单</a>&nbsp;&nbsp;<a href="yx_weixin_menu.php?actions=modi&id=<?php echo $rsdb[id]?>">修改</a>&nbsp;&nbsp;<a href="yx_weixin_menu.php?actions=del&id=<?php echo $rsdb[id]?>" onClick="return confirm('删除后不可恢复,你确实要删除吗?')">删除</a></td>
    </tr>
<?php
		$rs2=$db->excu("select * from mx_weixin_menu where fid='$rsdb[id]' order by orderid, id asc");
		if ($db->num_rows($rs2)>0){
			while ($rsdb2=$db->fetch_array($rs2)){
?>
    <tr class="list"> 
      <td width="35%">|__<?php echo $rsdb2["mname"]?></td>
      <td width="9%" align="center"><?php echo $MTYPE[$rsdb2["mtype"]]?></td>
      <td width="8%" align="center"> 
        <input type="text" name="listdb[<?php echo $rsdb2[id] ?>]" size="7" value="<?php echo $rsdb2['orderid']?>">
      </td>
      <td width="13%" align="center"><a href="yx_weixin_menu.php?actions=modi&id=<?php echo $rsdb2[id]?>">修改</a>&nbsp;&nbsp;<a href="yx_weixin_menu.php?actions=del&id=<?php echo $rsdb2[id]?>" onClick="return confirm('删除后不可恢复,你确实要删除吗?')">删除</a></td>
    </tr>
<?php
			}
		}
		}
	}
?>
<input type="hidden" name="actions" value="" />
</form>
</table>
<div class="t">
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
	<tr>
	<td>
	<div class="an1"><a href="yx_weixin_menu.php?actions=add">添加菜单</a></div>
	<div class="an2"><a href="javascript:document.form1.actions.value='list';document.form1.submit();">更新排序</a></div>
	<div class="an2"><a href="yx_weixin_menu.php?actions=set_wx">更新到微信</a></div>
	</td>
	</tr>
	</table>
</div>
			<div class="clear"></div>
			<div class="height10"></div>
</div>
<script type="text/javascript" src="/mxsoft/js/jquerys-1.5.1.js"></script>
<script language="javascript">
$(document).ready(function(){  
	$(".table_southidc tr").mouseover(function(){   
	$(this).addClass("list2");}).mouseout(function(){   
	$(this).removeClass("list2");}) //移除该行的class   
	$(".table_southidc tr:even").addClass("list1");   
});   
</script> 

<?php
}
?>
<div class="clear"></div>
<div class="height10"></div>
</div>
<?php require("../mx_foot.php");?>
<div class="clear"></div>
<div class="height10"></div>
</body>
</html>
